<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>生成.hta的Base64加密内容</title>
    <link href="/static/css/bootstrap3.4.1.min.css" rel="stylesheet">
    <script src="/static/js/vue.js"></script>
    <script src="/static/js/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/js/bootstrap.min.js"></script>
    <link rel="shortcut icon" href="/static/jiami.ico"/>
</head>
<body>
<div class="container text-center" id="app">
    <!--提交后碰到错误的弹窗-->
    <div class="alert alert-danger" role="alert" v-if="alert">
        <strong>友情提示！</strong> 提交内容不能为空
    </div>

    <!--提交后碰到错误的弹窗-->
    <div class="alert alert-danger" role="alert" v-if="error_msg!=''">
        <strong>提交失败！</strong> {{ error_msg }}
    </div>

    <!--提交成功的提示-->
    <div class="alert alert-success" role="alert" v-if="show && error_msg==''">
        <strong>加密成功！</strong> 请复制下面加密内容
    </div>

    <div id="result" v-if="show">
        <h2>执行结果</h2>
        <div class="row" v-if="content2">
            <div class="col-md-12">
                <h3>
                    <span class="label label-info">执行时间:{{exectime}}秒</span>
                </h3>
            </div>
        </div>

        <h3 v-if="content2">
            加密后内容&nbsp;&nbsp;&nbsp;&nbsp;
            <span class="label label-warning glyphicon glyphicon-copy" aria-hidden="true" style="cursor:pointer" @click.prevent="copyContent()">复制内容</span>&nbsp;
            <button type="button" class="btn btn-dark" onclick="window.location.href='<?php echo $backurl; ?>'">返回上一页</button>
        </h3>
        <div style="word-wrap: break-word;overflow-wrap: break-word;text-align: left;overflow-y:scroll;max-height: 800px;" v-if="content2">
            <code> {{ content2 }}</code>
        </div>
    </div>

    <h3 class="text-center text-warning">{{ topic }}</h3>

    <form class="form-horizontal">
        <div class="form-group">
            <input type="text" style="display:none!important" value="<?php echo $url; ?>" ref='requrl'>
            <textarea class="form-control" rows="10" id="content" name="content" v-model="content"
                      placeholder="https://de4.hatefemale.top/z240529_13/index.txt
或者
复制过来的劫持脚本">{{ content }}</textarea>
        </div>
        <div class="form-group row">
            <div class="col-lg-6">
                <button type="button" class="btn btn-default btn-lg" @click.prevent="reset()">重置</button>
            </div>
            <div class="col-lg-6">
                <button type="button" class="btn btn-primary btn-lg" @click.prevent="commit()" v-bind:disabled="btn_disabled?false:true">提交</button>
            </div>
        </div>
    </form>
</div>
</body>

<!-- 弹窗模板 -->
<div class="modal fade" id="autoCloseModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">提示</h4>
            </div>
            <div class="modal-body">
                复制成功
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
</html>

<script>
    let app = new Vue({
        el: "#app",
        data: {
            topic: '生成.hta的Base64加密内容',
            content: '',
            show: false,
            btn_disabled: true,
            alert: false,
            content2: '',
            exectime: '',
            error_msg: '',
            timer: null
        },
        methods: {
            showModal(){
                // 清除之前的定时器（如果有）
                if (this.timer) {
                    clearTimeout(this.timer);
                }
                // 显示模态框
                $('#autoCloseModal').modal('show');

                // 设置1.5秒后自动关闭
                this.timer = setTimeout(() => {
                    $('#autoCloseModal').modal('hide');
                }, 1500);
            },
            copyContent() {
                if (this.content2 == '') {
                    alert('加密生成失败，无法复制');
                    return false;
                }
                var oInput = document.createElement("textarea");
                oInput.value = this.content2;
                document.body.appendChild(oInput);
                oInput.select();
                document.execCommand("Copy");
                oInput.className = "oInput";
                oInput.style.display = "none";
                // alert("复制成功");
                this.showModal();
            },
            reset() {
                this.content = '';
                this.show = false;
                this.btn_disabled = true;
                this.alert = false;
            },
            commit() {
                // 请求url
                let url = this.$refs.requrl.value;
                this.btn_disabled = false;
                this.alert = false;
                if (this.content != '') {
                    this.show = false;
                    this.error_msg = '';
                    axios.post(url, {content: this.content}).then((response) => {
                        this.show = true;
                        if (response.data.code == 200) {
                            this.content2 = response.data.result.content;
                            this.exectime = response.data.result.exectime;
                            this.error_msg = '';
                            this.content = '';
                        } else {
                            this.content2 ='';
                            this.exectime ='';
                            this.error_msg = response.data.result;
                        }
                        this.btn_disabled = true;
                    });
                } else {
                    this.alert = true;
                    this.btn_disabled = true;
                }
            }
        }
    });
</script>